package thu.cs.segroup.agent.behaviour;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import thu.cs.segroup.util.Constants;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;

public class CommonSendObjMsgBehav extends OneShotBehaviour {

	private Serializable content;
	private List<String> destination;
	private String conversationId;
	private int tag;
	
	public CommonSendObjMsgBehav(Serializable _content, List<String> _destination, String _conversationId, int _tag, Agent agent) {
		super(agent);
		this.content = _content;
		this.destination = _destination;
		this.conversationId = _conversationId;
		this.tag = _tag;
	}
	
	@Override
	public void action() {
		ACLMessage msg = new ACLMessage(this.tag);
		msg.setLanguage(Constants.Object_Language);
		try {
			msg.setContentObject(content);
			msg.setConversationId(this.conversationId);
			for (int i = 0; i < destination.size(); i++) {
				msg.addReceiver(new AID(destination.get(i), AID.ISLOCALNAME));
			}
			myAgent.send(msg);
		} catch (IOException e) {
			e.printStackTrace();
		}
	
	}

}
